package com.briup.recognition.service.impl;

import com.briup.recognition.bean.BaseFile;
import com.briup.recognition.bean.BaseFileExample;
import com.briup.recognition.dao.BaseFileMapper;
import com.briup.recognition.service.IBaseFileService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BaseFileServiceImpl implements IBaseFileService {

    @Resource
    private BaseFileMapper baseFileMapper;


    @Override
    public List<BaseFile> query() {
        BaseFileExample example = new BaseFileExample();
        return baseFileMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(BaseFile baseFile) {
        BaseFileExample example = new BaseFileExample();
        BaseFileExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo("id",baseFile.getId());
        List<BaseFile> baseFiles = baseFileMapper.selectByExample(example);
        System.out.println(baseFiles);
        System.out.println("------------");
        if (baseFiles!=null && !baseFiles.isEmpty()){
            baseFileMapper.updateByPrimaryKey(baseFile);
        }
        else {
            baseFileMapper.insertSelective(baseFile);
        }

    }

    @Override
    public void deleteById(String id) {
        baseFileMapper.deleteByPrimaryKey(id);
    }
}
